﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;

public partial class Theme_3_ShowAllCommentAddFuC : System.Web.UI.Page
{
    PowerCreator.LMS.Web.Comment.Comment commentManager = new PowerCreator.LMS.Web.Comment.Comment();


    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            string commentid = Request.QueryString["CommentID"].ToString();
            ViewState["CommentID"] = commentid;
            ViewState["ResourceID"] = "0";
            BinderComment();
        }
    }

    /// <summary>
    /// 绑定主评论
    /// </summary>
    private void BinderComment()
    {
        PowerCreator.LMS.Comment.Entity.VOSysPLCommentInfo cinfo = commentManager.LoadComment(int.Parse(ViewState["CommentID"].ToString()));
        if (cinfo != null)
        {
            ViewState["ResourceID"] = cinfo.ResourceID.ToString();
            lblCreatedTime.Text = cinfo.CreatedTime.ToString();
            hypCreatedUserName.Text = cinfo.CreatedUserName;
            lblTitle.Text = cinfo.Title;
            lblContent.Text = cinfo.Content;
            lblLevel.Text = cinfo.CommentLevel.ToString();
            BinderFuComment(cinfo.CommentID);
            BinderHotComment();
        }
    }
    //绑定随机回复
    private void BinderHotComment()
    {
        string search = string.Format(" ResourceID= {0} and IsShow = 1 ", ViewState["ResourceID"]);
        string orderList = " CreatedTime desc ";
        DataTable dt = commentManager.QueryComment(search, orderList, PowerCreator.LMS.Web.Config.WebConfig.PageSize, 1);
        rpt_HotComment.DataSource = dt;
        rpt_HotComment.DataBind();
    }
    /// <summary>
    /// 绑定副评论
    /// </summary>    
    private void BinderFuComment(int commentid)
    {
        string search = string.Format("CommentID={0} and IsState= 1 ", commentid.ToString());        
        DataTable dt = commentManager.QueryFuComment(search);
        rptFuComment.DataSource = dt;
        rptFuComment.DataBind();
    }
    protected void btnAddNew_Click(object sender, EventArgs e)
    {
        try
        {
            if (Session[PowerCreator.LMS.Web.Config.WebConfig.SESSION_USER_USERINFO] == null)
            {
                PowerCreator.LMS.Common.Script.Script.Alert(Page,"nologin","未登录用户请重新登录!");
                return;
            }
            PowerCreator.LMS.Web.User.LoginEntity login = (PowerCreator.LMS.Web.User.LoginEntity)Session[PowerCreator.LMS.Web.Config.WebConfig.SESSION_USER_USERINFO];
             
            PowerCreator.LMS.Comment.Entity.VOSysPLFuCommentInfo fcinfog = new PowerCreator.LMS.Comment.Entity.VOSysPLFuCommentInfo();
            fcinfog.CommendCount = 0;
            fcinfog.CommentID = int.Parse(ViewState["CommentID"].ToString());
            fcinfog.CommentType = 0;
            fcinfog.Content = Request.Params["txtContent"].ToString();
            fcinfog.CreatedBy = login.UserID;
            fcinfog.CreatedIP = PowerCreator.LMS.Common.Utils.IPUtils.GetIP;
            fcinfog.CreatedUserName = login.UserName;
            fcinfog.CreatedRealName = login.AccountInfo.RealName;
            fcinfog.CreatedTime = DateTime.Now;
            fcinfog.DeleteState = 1;
            fcinfog.IsState = 0;
            fcinfog.LastUpdateBy = login.UserID;
            fcinfog.LastUpdateTime = DateTime.Now;
            fcinfog.StateCount = 0;

            string msg = "";
            int id = 0;
            if (commentManager.AddFuComment(fcinfog,ref id))
            {
                msg = "添加成功!";
            }
            else
            {
                msg = "添加失败!";
            }
            PowerCreator.LMS.Common.Script.Script.Alert(Page, "addnew", msg);

        }
        catch (Exception)
        {
            PowerCreator.LMS.Common.Script.Script.Alert(Page, "addnew", "添加数据出现异常!");
            
        }
    }
}
